<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('rule list')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="form">
					<input type="hidden" id="pageFlag" name="pageFlag" th:value="${rule.pageFlag}"/>
					<input type="hidden" id="type" name="type" value="DB"/>
					<div class="select-list">
						<ul>
							<li>
								考核组：
								<select name="khz" id="khz" th:with="dicts=${@dict.getType('rate_khz')}">
									<option value="">--请选择--</option>
									<option th:each="dict : ${dicts}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
										th:selected="${rule.khz == dict.dictValue}"></option>
								</select>
							</li>
							<!-- 
							<li>
								主办/督办：
								<select name="type" id="type" th:with="dicts=${@dict.getType('rate_kh_type')}">
									<option value="">--请选择--</option>
									<option th:each="dict : ${dicts}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
										th:selected="${rule.type == dict.dictValue}"></option>
								</select>
							</li>
							 -->
							<li>
								考核科室：<select name="dept.deptId">
									<option value="">--请选择--</option>
									<option th:each="dept : ${deptList}" th:text="${dept.deptName}" th:value="${dept.deptId}"
										th:selected="${rule.dept.deptId == dept.deptId}"></option>
								</select>
							</li>
							 <li>
								序号：<input type="text" name="xh"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<!-- 
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
								<a style="margin-left:20px;" class="btn btn-danger btn-rounded btn-sm" onclick="selectRuleForAdd()">
									<i class="fa fa-plus"></i> 新增
								</a>
								 -->
								<a style="margin-left:20px;" class="btn btn-info btn-rounded btn-sm" onclick="doExport()"
									th:if="${'MANAGE' == rule.pageFlag}">
									<i class="fa fa-download"></i> 导出规则
								</a>
								<a style="margin-left:20px;" class="btn btn-info btn-rounded btn-sm" onclick="importRule()"
									th:if="${'MANAGE' == rule.pageFlag}">
									<i class="fa fa-upload"></i> 导入规则
								</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<!-- 
	</div>
	 -->
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<script th:inline="javascript">
		var prefix = ctx + "rate/rule";
		var pageFlag = [[${rule.pageFlag}]];
		var typeDict = [[${@dict.getType('rate_kh_type')}]];
		var khzDict = [[${@dict.getType('rate_khz')}]];

		$(function() {
			queryRuleList();
		});
		function queryRuleList() {
			var options = {
				url: prefix + "/list",
				exportUrl: prefix + "/export",
				modalName: "考核细则",
				pagination: true,
				columns: [{
					field: 'id',
					visible: false
				},
				{
					field: 'khz',
					align: 'center',
					title: '考核组',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(khzDict, value);
					}
				},
				/**
				{
					field: 'type',
					align: 'center',
					title: '主办/督办',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(typeDict, value);
					}
				},
				**/
				{
					field: 'lb',
					align: 'center',
					title: '考核类别'
				},
				{
					field: 'dept.deptName',
					align: 'center',
					title: '考核部门'
				},
				{
					field: 'xm',
					align: 'left',
					title: '考核项目',
					formatter: function(value, row, index) {
						var spanBegin = "<span style='font-size:8px;'>";
						var spanEnd = "</span>";
						return spanBegin + value + spanEnd;
					}
				},
				{
					field: 'xh',
					align: 'center',
					title: '考核序号'
				},
				{
					field: 'fz',
					align: 'center',
					title: '考核分值'
				},
				{
					field: 'nr',
					align: 'left',
					title: '考核内容及标准',
					formatter: function(value, row, index) {
						var spanBegin = "<span style='font-size:8px;'>";
						var spanEnd = "</span>";
						return spanBegin + value + spanEnd;
					}
				},
				{
					field: 'fs',
					align: 'left',
					title: '考核方式',
					formatter: function(value, row, index) {
						var spanBegin = "<span style='font-size:10px;'>";
						var spanEnd = "</span>";
						return spanBegin + value + spanEnd;
					}
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						if ("MANAGE" == pageFlag) {
							actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						}
						// actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="remove(\'' + row.id + '\')"><i class="fa fa-times"></i>删除</a> ');
						// actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="view(\'' + row.id + '\')"><i class="fa fa-fa-angle-double-left"></i>查看</a> ');
						return actions.join('');
					}
				}]
			};
			$.table.init(options);
		}
		
		function edit(id) {
			$.modal.open("修改",
					prefix + "/edit?id=" + id + "&pageFlag=EDIT");
		}
		
		function doExport() {
			$.table.exportExcel();
		}
		
		function importRule() {
			var currentId = "importRuleForm";
			layer.open({
        		type: 1,
        		area: ['400px', '230px'],
        		fix: false,
        		//不固定
        		maxmin: true,
        		shade: 0.3,
        		title: '导入RULE',
        		content: $('#' + currentId).html(),
        		btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
        		// 弹层外区域关闭
        		shadeClose: true,
        		btn1: function(index, layero){
        			var file = layero.find('#file').val();
        			if (file == ''){
        				$.modal.msgWarning("请选择文件。");
        				return false;
        			}
        			var index = layer.load(2, {shade: false});
        			$.modal.disable();
        			var formData = new FormData();
        			formData.append("file", $('#file')[0].files[0]);
        			$.ajax({
        				url: prefix + "/importRule?khz=" + $("#khz").val() + "&type=" + $("#type").val(),
        				data: formData,
        				cache: false,
        				contentType: false,
        				processData: false,
        				type: 'POST',
        				success: function (result) {
        					if (result.code == web_status.SUCCESS) {
        						$.modal.closeAll();
        						$.modal.alertSuccess(result.msg);
        					} else if (result.code == web_status.WARNING) {
        						layer.close(index);
        						$.modal.enable();
    	                        $.modal.alertWarning(result.msg)
    	                    } else {
        						layer.close(index);
        						$.modal.enable();
        						$.modal.alertError(result.msg);
        					}
        				}
        			});
        		}
        	});
		}
	</script>
</body>
<script id="importRuleForm" type="text/template">
<form enctype="multipart/form-data" class="mt20 mb10">
	<div class="col-xs-offset-1">
		<input type="file" id="file" name="file"/>
		<div class="mt10 pt5">
		</div>
		<font color="red" class="pull-left mt10">
			提示：导入excel
		</font>
	</div>
</form>
</script>
</html>